package com.wc.alorithm_blue_bridge._排序.蓝桥大使;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/29 12:19
 * @description
 * https://www.lanqiao.cn/problems/20271/learning/?contest_id=250
 */
public class Main {
    /**
     * 思路：
     * 他们获得报酬也就是需要保证 两个 a[i] b[i] 差值尽可能小,
     * 那么我就可以用差值排序, 差值越大我们越需要选大的那一个
     * 剩下的被迫选另外一个
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[][] a = new int[N][3];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            a[i][0] = sc.nextInt();
            a[i][1] = sc.nextInt();
            a[i][2] = Math.abs(a[i][0] - a[i][1]);
        }
        Arrays.sort(a, 1, n + 1, Comparator.comparing(o->-o[2]));
        long sum = 0, l = 0, r = 0;
        int i = 1;
        while (l < n / 2 && r < n - n / 2) {
            if (a[i][0] > a[i][1]) {
                sum += a[i++][0];
                l++;
            } else {
                sum += a[i++][1];
                r++;
            }
        }
        while (l < n / 2) {
            sum += a[i++][0];
            l++;
        }
        while (r < n - n / 2) {
            sum += a[i++][1];
            r++;
        }
        out.println(sum);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

